<?php
header('Content-type: text/plain');

$res = array();
$ok = true;

// checking safe mode
$v = (bool) ini_get('safe_mode');
$res['safe_mode'] = array('is'=>(int) $v, 'ok'=>(int) ($v ? 0 : 1), 'mandatory'=>1);

// checking if the root folder is writable
$v = (bool) is_writable('../');
$res['readwrite'] = array('is'=>(int) $v, 'ok'=>(int) ($v ? 1 : 0), 'mandatory'=>1);

// checking if I can create subfolders
if ((bool) $v && !file_exists('../api/')) $v = (bool) @mkdir('../api/');
if ((bool) $v) $v = (bool) @mkdir('../api/test/');
if ((bool) $v) $v = (bool) @mkdir('../api/test/test/');
rmdir('../api/test/test/');
rmdir('../api/test/');
$res['subdirect'] = array('is'=>(int) $v, 'ok'=>(int) ($v ? 1 : 0), 'mandatory'=>1);

// checking outgoing connection
$connected = @fsockopen("www.xprogress.com", 80);
if ($connected){
	$v = true;
	fclose($connected);
}
else $v = false;
$res['outcnnect'] = array('is'=>(int) $v, 'ok'=>(int) ($v ? 1 : 0), 'mandatory'=>0);

// checking time limit
set_time_limit(0);
$v = (bool) ini_get('max_execution_time');
$res['maxextime'] = array('is'=>(int) $v, 'ok'=>(int) ($v ? 0 : 1), 'mandatory'=>0);

foreach ($res as $v) if (!(bool) $v['ok']) $ok = false;

if (!isset($print) || (bool) $print) echo json_encode($res);
else {
	$check = $res;
	unset($res);
}
?>